package net.zigin.nhi.could.waste.aop;

import net.zigin.nhi.could.waste.exception.UnauthorizedException;
import net.zigin.nhi.could.waste.vo.JsonForResult;
import org.apache.shiro.ShiroException;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 权限
 */
@Order(1)
@RestControllerAdvice()
public class LoginAdvice {


    /**
     * 捕捉shiro异常
     * @param e
     * @return
     */
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    @ExceptionHandler(ShiroException.class)
    public JsonForResult handle401(ShiroException e) {
        return JsonForResult.builder().success(false).message(e.getMessage()).build();
    }

    /**
     * 捕捉UnauthorizedException
     * @return
     */
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    @ExceptionHandler(UnauthorizedException.class)
    public JsonForResult handle401() {
        return JsonForResult.builder().success(false).message("401").build();
    }


}

